<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class UserBill extends Model
{
    use HasFactory;
    use PimpableTrait;
    //use SoftDeletes;

    /**
     * 可执行搜索的字段
     */
    public $searchable = [
        'user_id',
        'pm',
        'title',
        'status',
        'take',
        'type',
    ];

    /**
     * 账单状态
     */
    public $statusEnum=[
        'effective' => '有效',
        'invalid' => '无效',
        'determine' => '待确定'
    ];

    /**
     * 账单状态
     */
    public $typeEnum=[
        'promotionOrderCommission'=>'推广订单佣金',
        'promotionUserCommission'=>'推广用户佣金',
        'commissionWithdrawal'=>'佣金提现',
        'winningBalance'=>'中奖余额',
        'offlineCashier'=>'线下收银',
        'buyMember'=>'购买会员',
        'purchaseGoods'=>'购买商品',
        'balancePayment'=>'余额支付购买商品',
        'merchandiseRefund'=>'商品退款',
        'balanceRecharge'=>'用户余额充值',
        'shareRecords'=>'用户分享记录',
        'increaseBalance'=>'系统增加余额',
        'systemRefund'=>'系统退款',
    ];

    /**
     * 进行排序的字段
     */
    public $sortable =[
        'take',
        'status',
        'balance',
    ];

    /**
     * 可批量赋值字段
     */
    public $fillable = [
        'user_id',
        'link_id',
        'pm',
        'title',
        'category',
        'type',
        'number',
        'balance',
        'mark',
        'status',
        'take',
    ];

    /**
     * 默认使用倒叙的字段
     */
    public $defaultSortCriteria = [
        'id,desc',
    ];

    /**
     * 账单关联用户的id
     */
    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

}
